/******************************************************************************
//             INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//    Copyright(c) 2000 - 2001 Intel Corporation. All Rights Reserved.
//
//  VSS: 
//     $Workfile: $
//     $Revision: $
//     $Date:     $
//     $Archive:  $
//
//  Description:
//      Intel(R) Integrated Performance Primitives - JPEG Helper file.
//      This file contains inverse level shift functions for decoding. 
//
//  History:
//     Date         Author        Changes
//     2000/5/10    Jerry Hu      Created  (Version 0.1)
//     2001/2/12    Jerry Hu      Modified (Version 0.2)
//
********************************************************************************/
#include "_ippjpeg.h"

/*
#define _SHIFTLEVEL_16S16U(x, level) ((Ipp16s)((int)(x)+level))
IPPFUN(IppStatus, ippiShiftLevelInv_16s8u_C1R) (const Ipp16s *pSrcMCU,
                                                Ipp8u *pDst,
                                                int dstStep,
                                                const IppiRect *pRect)
{
    int x, y;
    int nWidth, nHeight, nOffset;
    int oleft, otop, oright, obottom;
    int left, top, right, bottom;
    Ipp8u *pDstPtr;
    IppiRect rect;

    _IPP_CHECK_ARG((pRect->left<pRect->right));
    _IPP_CHECK_ARG((pRect->top<pRect->bottom));

    oleft   = pRect->left;
    left    = pRect->left;
    otop    = pRect->top;
    top     = pRect->top;
    oright  = pRect->right;
    obottom = pRect->bottom;
    nOffset = 8*dstStep;

    for (y=0; y<obottom; ) {
        y+=8;
        bottom=(y<obottom)?y:obottom;
        nHeight=bottom-top;
        pDstPtr=pDst;
        for (x=0; x<oright; ) {
            x+=8;
            right=(x<oright)?x:oright;
            nWidth=right-left;
            if (8!=nWidth||8!=nHeight) {
                ippiShiftLevelInv_8x8_16s8u_C1R(pSrcMCU, pDstPtr, dstStep, &rect);
            } else {
                ippiShiftLevelInv_8x8_16s8u_C1(pSrcMCU, pDstPtr, dstStep);
            }
            left=x;
            pDstPtr+=8;
            pSrcMCU+=64;
        }
        left=oleft;
        top=y;
        pDst+=nOffset;
    }

    return IPP_STATUS_OK;
}
*/

/******************************************************************************
// Name:             ippiLevelShiftAdd128_8x8_16s8u_C1
// Description:      Convert each input sample from a two's complement representation to
//                   an unsigned representation.
// Input Arguments: 
//             pSrc: Identifies source data in 8x8.
//          dstStep: Indicates the step of destination image.
// Output Arguments:
//             pDst: Identifies destination block;
//                  
// Remarks:      
//                   1. The start address of "pSrc" shall be aligned at 4byte boundary.
//                   2. It is better to do this alignement at 32byte boundary to optimize 
//                      D-Cache accessing.
//                   
// Returns:         
//    IPP_STATUS_OK: Succeeds.
//
******************************************************************************/
IPPFUN(IppStatus, ippiLevelShiftAdd128_8x8_16s8u_C1) (const Ipp16s *pSrc,
                                                      Ipp8u *pDst,
                                                      int dstStep)
{
    int i;

    _IPP_CHECK_ARG(NULL!=pSrc && NULL!=pDst);
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrc));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pDst));
    _IPP_CHECK_ARG(0!=dstStep);

    for (i=0; i<8; i++) {
        pDst[0]=_IPP_SHIFTLEVEL_16S8U(pSrc[0]);
        pDst[1]=_IPP_SHIFTLEVEL_16S8U(pSrc[1]);
        pDst[2]=_IPP_SHIFTLEVEL_16S8U(pSrc[2]);
        pDst[3]=_IPP_SHIFTLEVEL_16S8U(pSrc[3]);
        pDst[4]=_IPP_SHIFTLEVEL_16S8U(pSrc[4]);
        pDst[5]=_IPP_SHIFTLEVEL_16S8U(pSrc[5]);
        pDst[6]=_IPP_SHIFTLEVEL_16S8U(pSrc[6]);
        pDst[7]=_IPP_SHIFTLEVEL_16S8U(pSrc[7]);
        pDst+=dstStep;
        pSrc+=8;
    } /* for (i=0; i<8; i++) */

    return IPP_STATUS_OK;
}

/******************************************************************************
// Name:             ippiLevelShiftAdd128_8x8_16s8u_C1R
// Description:      Convert each input sample from a two's complement representation to
//                   an unsigned representation.  It processes ROI in 8x8 block.
// Input Arguments: 
//             pSrc: Identifies source data in 8x8.
//          dstStep: Indicates the step of destination image.
//          roiSize: Indicates the size of the rectangle that need to be copied. 
//
// Output Arguments:
//             pDst: Identifies destination block;
//                  
// Remarks:      
//                   1. The start address of "pSrc" shall be aligned at 4byte boundary.
//                   2. It is better to do this alignement at 32byte boundary to optimize 
//                      D-Cache accessing.
//                   
// Returns:         
//    IPP_STATUS_OK: Succeeds.
//
******************************************************************************/
IPPFUN(IppStatus, ippiLevelShiftAdd128_8x8_16s8u_C1R) (const Ipp16s *pSrc,
                                                       Ipp8u *pDst,
                                                       int dstStep,
                                                       IppiSize roiSize)
{
    int i, j;
    int bottom, right;
    Ipp8u *pDstPtr;

    _IPP_CHECK_ARG(NULL!=pSrc && NULL!=pDst);
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pSrc));
    _IPP_CHECK_ARG(_IPP_CHECK_ALIGN_4BYTE(pDst));
    _IPP_CHECK_ARG(0!=dstStep);
    _IPP_CHECK_ARG((0<roiSize.width)  && (8>=roiSize.width));
    _IPP_CHECK_ARG((0<roiSize.height) && (8>=roiSize.height));


    bottom=roiSize.height;
    right=roiSize.width;

    for (i=0; i<bottom; i++) {
        pDstPtr=pDst;
        for (j=0; j<right; j++) {
            *pDstPtr++=_IPP_SHIFTLEVEL_16S8U(pSrc[j]);
        }
        pSrc+=8;
        pDst+=dstStep;
    }

    return IPP_STATUS_OK;
}

/* EOF */
